﻿'******************************************************************************
'
'    Copyright (C) 2009, Raul Cicuendez Gil
'    http://www.codeplex.com/SimpleJQueryNET
'
'    This program is free software: you can redistribute it and/or modify
'    it under the terms of the GNU General Public License as published by
'    the Free Software Foundation, either version 3 of the License, or
'    any later version.'
'
'    This program is distributed in the hope that it will be useful,
'    but WITHOUT ANY WARRANTY; without even the implied warranty of
'    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'    GNU General Public License for more details.
'
'    You should have received a copy of the GNU General Public License
'    along with this program.  If not, see <http://www.gnu.org/licenses/>.
'    http://www.codeplex.com/SimpleJQueryNET
'******************************************************************************
Public Class JQCommands
    'EXAMPLE
    '   <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    '    <div id="commandsmenu" class="ui-widget ui-helper-clearfix"></div>
    '    <asp:LinkButton ID="LinkButton1" runat="server">LinkButton</asp:LinkButton>
    '    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    '    <asp:Button ID="Button1" runat="server" Text="Button" />  

    '</asp:Content>
    Private _btnString As String = "<div id=""cmd{0}""><div id=""icocmd{0}""></div>&nbsp;{1}&nbsp;</div>"
    Private _btnInputHidden As String = "<input type=""hidden"" name=""command"" id=""command"" value=""{0}"" />"
    Private _J As JQuery

    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="fIdButton"></param>
    ''' <param name="fsTexto"></param>
    ''' <param name="fsIcono"></param>
    ''' <param name="fForm"></param>
    ''' <remarks></remarks>
    '''
    Public Sub AddButton(ByVal fIdButton As String, ByVal fsTexto As String, ByVal fsIcono As String, ByVal fsJQCode As String, Optional ByVal fbRemove As Boolean = True)
        Dim btn As String = JQUtils.CheckQuotes(String.Format(_btnString, fIdButton, fsTexto))
        Dim hidd As String = JQUtils.CheckQuotes(String.Format(_btnInputHidden, fIdButton))
        Dim jqcode As String
        Dim jj As New JQuery
        Dim Jas As New JQMyAssistant(_J)
        'añado el boton 
        _J.S("#commandsmenu").append(btn)
        'añado el onclick
        'remove prevents that teh input command remains if dialog confirm is false
        'fsJQCode es el código JQ del botón.
        jqcode = jj.S("#commandsmenu").append(hidd) & fsJQCode
        If fbRemove Then
            jqcode = jqcode & "$(""#command"").remove();"
        End If
        _J.S("#cmd" & fIdButton).click(JQUtils.GetFunction(jqcode))
        _J.S("#cmd" & fIdButton).css2(JQUtils.GetOptions("'float'", "'left'", "'margin'", "'5px'"))
        'y le doy formato
        _J.AddStyle_UIAllCss()
        Jas.CssCorner("#cmd" & fIdButton)
        Jas.CssCornerAddHoverEvent("#cmd" & fIdButton)
        _J.S("#cmd" & fIdButton).css2(JQUtils.GetOptions("'width'", "'" & ((fsTexto.Length * 10) + 18) & "px'", "'height'", "'16px'"))
        '
        Jas.GetIcon("#icocmd" & fIdButton, fsIcono)
        _J.S("#icocmd" & fIdButton).css2(JQUtils.GetOptions("'width'", "'18px'", "'float'", "'left'"))
        ''
    End Sub
    Public Sub AddButton(ByVal fIdButton As String, ByVal fsTexto As String, ByVal fsIcono As String, ByVal fForm As System.Web.UI.HtmlControls.HtmlForm)
        Me.AddButton(fIdButton, fsTexto, fsIcono, JQUtils.Form.Post(fForm))
    End Sub
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="fsTexto"></param>
    ''' <remarks></remarks>
    Public Sub SetInfo(ByVal fsTexto As String)
        _J.S("#commandsmenu").after(JQUtils.messages.GetInfoMessage("Aviso: ", fsTexto))
    End Sub
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="fsTexto"></param>
    ''' <remarks></remarks>
    Public Sub SetError(ByVal fsTexto As String)
        _J.S("#commandsmenu").after(JQUtils.messages.GetErrorMessage("Error: ", fsTexto))
    End Sub
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="fsTexto"></param>
    ''' <remarks></remarks>
    Public Sub SetMessage(ByVal fsTexto As String)
        _J.S("#commandsmenu").after(JQUtils.messages.GetMessage("cmmessage", "Mensaje: ", fsTexto))
        _J.RawJQCode(JQUtils.effects.MakeMessageEffect(".cmmessage"))
    End Sub
    ''' <summary>
    ''' 
    ''' </summary>
    ''' <param name="fJQ"></param>
    ''' <remarks></remarks>
    Public Sub New(ByVal fJQ As JQuery)
        _J = fJQ
    End Sub
End Class

